package com.example.shop.controller;

import com.example.shop.entity.Product;
import com.example.shop.service.ProductService;
import com.example.shop.service.QiniuService;
import com.example.shop.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @Autowired
    private QiniuService qiniuService;

    @PostMapping("add")
    public JsonResult add(@RequestBody Product product) {
        int result = productService.addproduct(product);
        if (result == 0) {
            JsonResult.failed("添加失败");
        }
        return JsonResult.success("添加成功",null);
    }

    @GetMapping("list")
    public JsonResult list() {
        List<Product> productList = productService.getProductList();
        return JsonResult.success("获取成功",productList);
    }

}
